class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> pq;
        for (auto x : stones)
            pq.push(x);
        while (pq.size() > 1)
        {
            int top1 = pq.top();
            pq.pop();
            int top2 = pq.top();
            pq.pop();

            int ret = top1 - top2;
            if (ret)
                pq.push(ret);
        }

        return pq.size() == 0 ? 0 : pq.top();
    }
};